package com.yjc.drygoods.product.app;

import java.util.Arrays;
import java.util.Map;

import com.yjc.common.utils.PageUtils;
import com.yjc.drygoods.product.vo.SpuSaveVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.yjc.drygoods.product.entity.SpuInfoEntity;
import com.yjc.drygoods.product.service.SpuInfoService;
import com.yjc.common.utils.R;


/**
 * spu信息
 *
 * @author yjc
 * @email yjc19979401754@126.com
 * @date 2022-08-19 21:27:48
 */
@RestController
@RequestMapping("product/spuinfo")
public class SpuInfoController {
    @Autowired
    private SpuInfoService spuInfoService;

    /**
     * /product/spuinfo/{spuId}/down
     * 干货上下架
     */
    @GetMapping("/{spuId}/down")
    public R downSkuInfo(@PathVariable("spuId") Long spuId) {
        spuInfoService.downSkuInfo(spuId);
        return R.ok();
    }

    /**
     * /product/spuinfo/{spuId}/up
     * 干货上架
     */
    @PostMapping("/{spuId}/up")
    public R upSkuInfo(@PathVariable("spuId") Long spuId) {
        spuInfoService.upSkuInfo(spuId);
        return R.ok();
    }

    /**
     * /product/spuinfo/list
     * spu检索
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = spuInfoService.queryPageByCondition(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{spuId}")
    public R spuInfo(@PathVariable("spuId") Long spuId) {
        SpuInfoEntity spuInfo = spuInfoService.getById(spuId);

        return R.ok().put("spuInfo", spuInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SpuSaveVo spuSaveVo) {
        spuInfoService.saveSpuInfo(spuSaveVo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SpuInfoEntity spuInfo) {
        spuInfoService.updateById(spuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        spuInfoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
